import {
  Module,
  NestModule,
  MiddlewareConsumer,
  RequestMethod,
} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { YuiModule } from './yui/yui.module';
import { YuicModule } from './yuic/yuic.module';
import { ConfigModule } from './config/config.moudle';
import { Loginmiddleware } from './middlerware/login.middleware';
import { UploadMiddleware } from './middlerware/upload.middleware';
import { UploadModule } from './upload/upload.module';
import { HttpexceptionModule } from './httpexception/httpexception.module';
import { APP_GUARD } from '@nestjs/core';
// import { RolesGuard } from './guard/roles.guard';
import { PModule } from './p/p.module';
import { GuradModule } from './gurad/gurad.module';
//数据库
import { TypeOrmModule } from '@nestjs/typeorm';
import { Guard } from './gurad/entities/gurad.entity';
import { Upload } from './upload/entities/upload.entity';

@Module({
  imports: [
    YuiModule,
    YuicModule,
    ConfigModule.GetPath({ path: '成功' }),
    UploadModule,
    HttpexceptionModule,
    PModule,
    GuradModule,
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '1314LOVEyui',
      database: 'yuitestbase64',
      // entities: [__dirname + '/**/*.entity{.ts,.js}'], //实体文件
      entities: [Guard, Upload],
      synchronize: true,
    }),
  ],
  controllers: [AppController],
  providers: [
    AppService,
    //模块
    // {
    //   provide: APP_GUARD,
    //   useClass: RolesGuard,
    // },
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(UploadMiddleware, Loginmiddleware)
      .forRoutes({ path: 'yui', method: RequestMethod.POST });
  }
}
